package com.diredevs;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * UFRN Calculator!!!
 * :D
 */
public class App 
{
	public static BufferedReader in;

	private static float calculateMedia(float gradeOne, float gradeTwo, float gradeThree){
		float media = (gradeOne+gradeTwo+gradeThree)/3;
		return media;
	}
	
	public static boolean checkApproval(float gradeOne, float gradeTwo, float gradeThree, float gradeRec){
		float media = calculateMedia(gradeOne, gradeTwo, gradeThree);
		
		if(media >= 7)
			return true;
		else if(media >= 5 && (gradeOne >= 3) && (gradeTwo >= 3) && (gradeThree >= 3))
			return true;
		else{
			//Trocar menor nota por reposição
			if((gradeOne <= gradeTwo) && (gradeOne <= gradeThree))
				gradeOne = gradeRec;
			else if((gradeTwo <= gradeOne) && (gradeTwo <= gradeThree))
				gradeTwo = gradeRec;
			else
				gradeThree = gradeRec;
			
			media = calculateMedia(gradeOne, gradeTwo, gradeThree);
			
			if(media >= 7)
				return true;
			else if(media >= 5 && (gradeOne >= 3) && (gradeTwo >= 3) && (gradeThree >= 3))
				return true;
			else
				return false;
		}		
	}
/*
	private static float calculateMedia(float gradeOne, float gradeTwo, float gradeThree){
		float media = (gradeOne*4 + gradeTwo*5 + gradeThree*6)/15;
		return media;
	}
	
	public static boolean checkApproval(float gradeOne, float gradeTwo, float gradeThree, float gradeRec) throws NumberFormatException, IOException{
		float media = calculateMedia(gradeOne, gradeTwo, gradeThree);
		if(media >= 7)
			return true;
		else if (media < 3)
			return false;
		else{
			float res = (media+gradeRec)/2;
			
			if(res >=5)
				return true;
			else
				return false;
		}
	}
	*/
    public static void main( String[] args ) throws NumberFormatException, IOException
    {
    	in = new BufferedReader(new InputStreamReader(System.in));
		
		System.out.println("Nota da primeira unidade: ");
		float gradeOne = Float.parseFloat(in.readLine());
		System.out.println("Nota da segunda unidade: ");
		float gradeTwo = Float.parseFloat(in.readLine());
		System.out.println("Nota da terceira unidade: ");
		float gradeThree = Float.parseFloat(in.readLine());
		System.out.println("Nota da recuperação (zero caso não exista): ");
		float gradeRec = Float.parseFloat(in.readLine());
    	
    	if(checkApproval(gradeOne, gradeTwo, gradeThree, gradeRec))
    		System.out.println("Parabéns, você foi aprovado!");
    	else
    		System.out.println("Infelizmente você foi reprovado!");
    }
}
